#ifndef SQLCONNRAII_H
#define SQLCONNRAII_H

#include "sqlconnpool.h"

class SqlConnRAII {
public:
    SqlConnRAII(MYSQL** sql, SqlConnPool* connPool) 
    {
        assert(connPool);
        *sql = connPool->getConn();
        sql_ = *sql;
        connPool_ = connPool;
    }

    ~SqlConnRAII() 
    {
        if(sql_) {
            connPool_->freeConn(sql_);
        }
    }
private:
    MYSQL* sql_;
    SqlConnPool* connPool_;
};

#endif